package antani.client.pages;

import antani.client.GWTClient;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.PopupPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class PlayOpenPopup {

	PopupPanel popupPanel = new PopupPanel(true, true);
	private String albumId;

	Anchor playlistLink = new Anchor("playlist", "/");

	public void setHandlerAndShow(String title, String albumId) {
		this.albumId = albumId;
		popupPanel.setTitle(title);
		popupPanel.center();
		playlistLink.setHref("/player.m3u?getM3U=" + albumId);
	}

	public PlayOpenPopup() {

		VerticalPanel vp = new VerticalPanel();
		Label playLabel = new Label("play @home");

		playLabel.setStyleName("popupItem");
		playlistLink.setStyleName("popupItem");

		playLabel.addClickHandler(new ClickHandler() {
			@Override
			public void onClick(ClickEvent event) {
				popupPanel.hide();
				GWTClient.playerPage.playAlbum(albumId);
			}
		});

		vp.add(playLabel);
		vp.add(playlistLink);

		popupPanel.setAutoHideEnabled(true);
		popupPanel.setStyleName("popupPanel");
		popupPanel.setWidget(vp);

		popupPanel.center();
	}
}
